package com.luke.star.persist.mapper;

import com.luke.star.persist.po.StAssignment;
import com.luke.star.persist.po.StAssignmentExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface StAssignmentMapper {
    @SelectProvider(type=StAssignmentSqlProvider.class, method="countByExample")
    long countByExample(StAssignmentExample example);

    @DeleteProvider(type=StAssignmentSqlProvider.class, method="deleteByExample")
    int deleteByExample(StAssignmentExample example);

    @Delete({
        "delete from st_assignment",
        "where assi_id = #{assiId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String assiId);

    @Insert({
        "insert into st_assignment (assi_id, assi_task_id, ",
        "assi_create_time, assi_update_time, ",
        "assi_desc, assi_state, ",
        "assi_expect_num, assi_task_model, ",
        "assi_circle_model, assi_run_time)",
        "values (#{assiId,jdbcType=VARCHAR}, #{assiTaskId,jdbcType=VARCHAR}, ",
        "#{assiCreateTime,jdbcType=TIMESTAMP}, #{assiUpdateTime,jdbcType=TIMESTAMP}, ",
        "#{assiDesc,jdbcType=VARCHAR}, #{assiState,jdbcType=CHAR}, ",
        "#{assiExpectNum,jdbcType=INTEGER}, #{assiTaskModel,jdbcType=CHAR}, ",
        "#{assiCircleModel,jdbcType=CHAR}, #{assiRunTime,jdbcType=INTEGER})"
    })
    int insert(StAssignment record);

    @InsertProvider(type=StAssignmentSqlProvider.class, method="insertSelective")
    int insertSelective(StAssignment record);

    @SelectProvider(type=StAssignmentSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="assi_id", property="assiId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="assi_task_id", property="assiTaskId", jdbcType=JdbcType.VARCHAR),
        @Result(column="assi_create_time", property="assiCreateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="assi_update_time", property="assiUpdateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="assi_desc", property="assiDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="assi_state", property="assiState", jdbcType=JdbcType.CHAR),
        @Result(column="assi_expect_num", property="assiExpectNum", jdbcType=JdbcType.INTEGER),
        @Result(column="assi_task_model", property="assiTaskModel", jdbcType=JdbcType.CHAR),
        @Result(column="assi_circle_model", property="assiCircleModel", jdbcType=JdbcType.CHAR),
        @Result(column="assi_run_time", property="assiRunTime", jdbcType=JdbcType.INTEGER)
    })
    List<StAssignment> selectByExample(StAssignmentExample example);

    @Select({
        "select",
        "assi_id, assi_task_id, assi_create_time, assi_update_time, assi_desc, assi_state, ",
        "assi_expect_num, assi_task_model, assi_circle_model, assi_run_time",
        "from st_assignment",
        "where assi_id = #{assiId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="assi_id", property="assiId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="assi_task_id", property="assiTaskId", jdbcType=JdbcType.VARCHAR),
        @Result(column="assi_create_time", property="assiCreateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="assi_update_time", property="assiUpdateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="assi_desc", property="assiDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="assi_state", property="assiState", jdbcType=JdbcType.CHAR),
        @Result(column="assi_expect_num", property="assiExpectNum", jdbcType=JdbcType.INTEGER),
        @Result(column="assi_task_model", property="assiTaskModel", jdbcType=JdbcType.CHAR),
        @Result(column="assi_circle_model", property="assiCircleModel", jdbcType=JdbcType.CHAR),
        @Result(column="assi_run_time", property="assiRunTime", jdbcType=JdbcType.INTEGER)
    })
    StAssignment selectByPrimaryKey(String assiId);

    @UpdateProvider(type=StAssignmentSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") StAssignment record, @Param("example") StAssignmentExample example);

    @UpdateProvider(type=StAssignmentSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") StAssignment record, @Param("example") StAssignmentExample example);

    @UpdateProvider(type=StAssignmentSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(StAssignment record);

    @Update({
        "update st_assignment",
        "set assi_task_id = #{assiTaskId,jdbcType=VARCHAR},",
          "assi_create_time = #{assiCreateTime,jdbcType=TIMESTAMP},",
          "assi_update_time = #{assiUpdateTime,jdbcType=TIMESTAMP},",
          "assi_desc = #{assiDesc,jdbcType=VARCHAR},",
          "assi_state = #{assiState,jdbcType=CHAR},",
          "assi_expect_num = #{assiExpectNum,jdbcType=INTEGER},",
          "assi_task_model = #{assiTaskModel,jdbcType=CHAR},",
          "assi_circle_model = #{assiCircleModel,jdbcType=CHAR},",
          "assi_run_time = #{assiRunTime,jdbcType=INTEGER}",
        "where assi_id = #{assiId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(StAssignment record);
    
    //---------------------------add by human
    
    
    @Select({
    	"select a.* from st_assignment a", 
    	"where a.assi_state='00'",
    	"and exists(select 1 from st_task t where t.id=a.assi_task_id and t.state='00')",
    	"and not exists(select 1 from st_assignment_log l where l.assi_id=a.assi_id and l.create_time between CURDATE() and date_add(CURDATE(), interval 1 day))",
    })
    @Results({
    	@Result(column="assi_id", property="assiId", jdbcType=JdbcType.VARCHAR, id=true),
    	@Result(column="assi_task_id", property="assiTaskId", jdbcType=JdbcType.VARCHAR),
    	@Result(column="assi_create_time", property="assiCreateTime", jdbcType=JdbcType.TIMESTAMP),
    	@Result(column="assi_update_time", property="assiUpdateTime", jdbcType=JdbcType.TIMESTAMP),
    	@Result(column="assi_desc", property="assiDesc", jdbcType=JdbcType.VARCHAR),
    	@Result(column="assi_state", property="assiState", jdbcType=JdbcType.CHAR),
    	@Result(column="assi_expect_num", property="assiExpectNum", jdbcType=JdbcType.INTEGER),
    	@Result(column="assi_task_model", property="assiTaskModel", jdbcType=JdbcType.CHAR),
    	@Result(column="assi_circle_model", property="assiCircleModel", jdbcType=JdbcType.CHAR),
    	@Result(column="assi_run_time", property="assiRunTime", jdbcType=JdbcType.INTEGER)
    })
   List<StAssignment> queryRunAssignment();
    
    
    
    
    
    
    
    
}